<!--  -->
<template>
  <div style="padding-top:100px">
    <div class="app-title-container title-position">
      <modules-title titleName="放/取样计划详情">
        <template slot="btn">
          <el-button class="filter-item" plain=""  size="small"
            @click="handleBack">返回
          </el-button>
          <el-button type="primary" icon="el-icon-open" size="small" @click="changeStability" v-if="isShow&&((data.plan.status!=2)&&(data.plan.status!=1))&&data.plan.instrument.instrument_id!=''">更换考察设备
          </el-button>
        </template>
      </modules-title>
    </div>

    <div style="padding:20px">
      <el-form label-width="180px" size="small" :label-position="left">
        <el-row :gutter="80">
          <el-col :span="8">
            <el-form-item label="计划编号：">
              <span>{{data.plan.plan_no}}</span>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="样品名称：">
              <span>{{data.plan.sample_info.sample_name}}</span>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="规格：">
              <span>{{data.plan.sample_info.sample_attrs}}</span>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="批号/批量：">
            <div style="display: flex;flex-wrap: wrap;" v-if="data.plan.batch_info!=null">
                <div v-for="(item,index) in data.plan.batch_info" :key=index>
                  <span>{{item.sample_batch}}/{{item.batch_num}}</span>
                  <span v-if="data.plan.batch_info.length-1!=index">,</span>
                </div>
              </div>
              <!-- <span>{{data.plan.sample_batch.batch_number/data.plan.sample_batch.batch_num}}</span> -->
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="项目名称：">
              <span>{{data.plan.project_name}}</span>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="项目负责人：">
              <span>{{data.plan.project_leader_name	}}</span>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="稳定性方案：">
              <span>{{data.plan.stability_scheme_name}}</span>
            </el-form-item>
          </el-col>
           <el-col :span="8">
            <el-form-item label="方案编号：">
              <span>{{data.plan.scheme_code}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="稳定性考察类型：">
              <span>{{data.plan.inspect_type.inspect_type_name}}</span>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="放置条件：">
              <span>{{data.plan.place_conditions.place_conditions_name}}</span>
            </el-form-item>
          </el-col>

          <el-col :span="8" v-if="data.plan.instrument!=null&&data.plan.instrument.instrument_no!=''">
            <el-form-item label="稳定性箱编号：">
              <span v-if='data.plan.instrument!=null'>{{data.plan.instrument.instrument_no}}</span>
            </el-form-item>
          </el-col>
           <el-col :span="8" v-if="data.plan.instrument!=null&&data.plan.instrument.instrument_name!=''">
            <el-form-item label="稳定性箱名称：">
              <span v-if='data.plan.instrument!=null'>{{data.plan.instrument.instrument_name}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="data.plan.in_packing!=null">
            <el-form-item label="直接接触包材：">
              <div style="display: flex;flex-wrap: wrap;" v-if="data.plan.in_packing!=null">
                <div v-for="(item,index) in data.plan.in_packing.in_sealing_ary" :key=index>
                  {{item.in_sealing}}
                  <span v-if="data.plan.in_packing.in_sealing_ary.length-1!=index">,</span>
                </div>
              </div>
            </el-form-item>
          </el-col>

          <el-col :span="8" v-if="data.plan.in_packing!=null">
            <el-form-item label="直接接触包材封口形式：" >
              <div style="display: flex;flex-wrap: wrap;" v-if="data.plan.in_packing!=null">
                <div v-for="(item,index) in data.plan.in_packing.in_packing_material_ary" :key=index>
                  {{item.in_packing_material}}
                  <span v-if="data.plan.in_packing.in_packing_material_ary.length-1!=index">,</span>
                </div>
              </div>
            </el-form-item>
          </el-col>

          <el-col :span="8" v-if="data.plan.out_packing!=null&&data.plan.if_packing==1">
            <el-form-item label="非直接接触包材：">
              <div style="display: flex;flex-wrap: wrap;" v-if="data.plan.out_packing!=null">
                <div v-for="(item,index) in data.plan.out_packing.out_sealing_ary" :key=index>
                  {{item.out_sealing}}
                  <span v-if="data.plan.out_packing.out_sealing_ary.length-1!=index">,</span>
                </div>
              </div>
            </el-form-item>
          </el-col>

          <el-col :span="8" v-if="data.plan.out_packing!=null&&data.plan.if_packing==1">
            <el-form-item label="非直接接触包材封口形式：">
              <div style="display: flex;flex-wrap: wrap;" v-if="data.plan.out_packing!=null">
                <div v-for="(item,index) in data.plan.out_packing.out_packing_material_ary" :key=index>
                  {{item.out_packing_material}}
                  <span v-if="data.plan.out_packing.out_packing_material_ary.length-1!=index">,</span>
                </div>
              </div>
            </el-form-item>
          </el-col>

          <el-col :span="8" v-if="data.plan.secondary_measure_name!=''">
            <el-form-item label="辅助措施：">
              <span>{{data.plan.secondary_measure_name}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">

          </el-col>
        </el-row>
      </el-form>
      <item-title title="放/取样明细记录" :borderShow="false" />
      <!-- 表格 -->
      <el-table :data="tableData" style="width: 100%;margin-top:-12px" size="medium" border @row-click="rowClick" :cell-style="cellStyle">

        <!-- <el-table-column prop="batch_no" label="批号" align="center">
          <template slot-scope="scope">
             <div style="display: flex;flex-wrap: wrap;justify-content:center">
                <div v-for="(item,index) in scope.row.batch_no" :key=index>
                  {{item}}
                  <span v-if="scope.row.batch_no.length-1!=index">、</span>
                </div>
              </div>
          </template>
        </el-table-column> -->
        <el-table-column prop="prop" label="考察点" align="center">
          <template slot-scope="scope">
             <span v-if="scope.row.sample_point_num=='0'&&scope.row.sample_point_unit=='0'">-</span>
             <span v-else>
               <span>{{scope.row.sample_point_num}}</span><span v-if="scope.row.sample_point_unit=='1'">天</span><span v-if="scope.row.sample_point_unit=='2'">月</span>
             </span>
          </template>
        </el-table-column>
        <el-table-column prop="operation_time" label="应放/取样日期" align="center">
          <template slot-scope="scope">
            <span>{{ dateFormat1('yyyy-mm-dd',scope.row.operation_time) }}</span>
          </template>
        </el-table-column>

        <el-table-column prop="last_operation_time" label="最迟放/取样日期" align="center">
          <template slot-scope="scope">
            <span>{{ dateFormat1('yyyy-mm-dd',scope.row.last_operation_time) }}</span>
          </template>
        </el-table-column>

        <el-table-column prop="operation_type" label="类型" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.operation_type=='1'">放样</span>
            <span v-if="scope.row.operation_type=='2'">取样</span>
          </template>
        </el-table-column>

        <el-table-column prop="act_opera_time" label="实际放/取样日期" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.operation_type=='1'">
              <div v-if="scope.row.operation_record!=null&& scope.row.status!=0">
                  <span>{{ dateFormat1('yyyy-mm-dd',scope.row.operation_record[0].act_opera_time) }}</span>
              </div>
            </div>
             <div v-if="scope.row.operation_type=='2'">
              <div v-if="scope.row.operation_record!=null&& scope.row.status!=0">
                  <span>{{ dateFormat1('yyyy-mm-dd',scope.row.operation_record[0].act_opera_time) }}</span>
              </div>
            </div>
          </template>
        </el-table-column>

        <el-table-column prop="operation_num" label="本次放/取样数量" align="center">
           <template slot-scope="scope" >
              <!-- <span v-if="scope.row.status!=0">{{scope.row.operation_num}}</span> -->
              <div v-if="scope.row.operation_type=='2'">
                <div v-if="scope.row.status!=0">
                    <!-- <span v-if="data.plan.sample_info.packaging_nu_unit!=''">{{scope.row.operation_num}}{{data.plan.sample_info.packaging_nu_unit}}</span>
                    <span v-else>{{scope.row.operation_num}}{{data.plan.sample_info.packaging_unit}}</span> -->
                    <span>{{scope.row.operation_num}}{{data.plan.sample_info.packaging_unit}}</span>
                </div>
              </div>
              <div v-if="scope.row.operation_type=='1'">
                <div v-if="scope.row.status!=0">
                    <!-- <span v-if="data.plan.sample_info.packaging_nu_unit!=''">{{scope.row.operation_num}}{{data.plan.sample_info.packaging_nu_unit}}</span>
                    <span v-else>{{scope.row.operation_num}}{{data.plan.sample_info.packaging_unit}}</span> -->
                    <span>{{scope.row.operation_num}}{{data.plan.sample_info.packaging_unit}}</span>
                </div>
              </div>
           </template>
        </el-table-column>

        <el-table-column prop="surplus_num" label="剩余量" align="center">
           <template slot-scope="scope">
            <div v-if="scope.row.operation_type=='2'">
                <div v-if="scope.row.status!=0">
                    <!-- <span v-if="data.plan.sample_info.packaging_nu_unit!=''">{{scope.row.surplus_num}}{{data.plan.sample_info.packaging_nu_unit}}</span>
                    <span v-else>{{scope.row.surplus_num}}{{data.plan.sample_info.packaging_unit}}</span> -->
                    <span >{{scope.row.surplus_num}}{{data.plan.sample_info.packaging_unit}}</span>
                </div>
              </div>
              <div v-if="scope.row.operation_type=='1'">
                <div v-if="scope.row.status!=0">
                   <span>{{scope.row.surplus_num}}{{data.plan.sample_info.packaging_unit}}</span>
                    <!-- <span v-if="data.plan.sample_info.packaging_nu_unit!=''">{{scope.row.surplus_num}}{{data.plan.sample_info.packaging_nu_unit}}</span>
                    <span v-else>{{scope.row.surplus_num}}{{data.plan.sample_info.packaging_unit}}</span> -->
                </div>
              </div>
             <!-- <span v-if="data.plan.sample_info.packaging_nu_unit!=''">{{scope.row.surplus_num}}{{data.plan.sample_info.packaging_nu_unit}}</span>
             <span v-else>{{scope.row.surplus_num}}{{data.plan.sample_info.packaging_unit}}</span> -->
           </template>
        </el-table-column>

        <el-table-column prop="status" label="状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.status=='0'&&scope.row.operation_type=='1'">未放样</span>
            <span v-if="scope.row.status=='0'&&scope.row.operation_type=='2'">未取样</span>
            <span v-if="scope.row.status=='1'">待复核</span>
            <span v-if="scope.row.status=='2'">已放样</span>
            <span v-if="scope.row.status=='3'">检验中</span>
            <span v-if="scope.row.status=='4'">已检验</span>
            <span v-if="scope.row.status=='5'">已结束</span>
            <span v-if="scope.row.status=='6'">已取消</span>
          </template>
        </el-table-column>

        <el-table-column prop="operation_user_name" label="放/取样操作人" align="center">
         <template slot-scope="scope">
           <span v-if="scope.row.operation_record!=null">{{scope.row.operation_record[0].operation_user_name}}</span>
          </template>
        </el-table-column>

        <el-table-column label="操作" width="300" align="center">
          <template slot-scope="scope">
            <!-- <el-button type="text" icon="el-icon-view"
            @click="f(scope.row.id)"
            v-hasPermi="{v:['fangyang:option'],isF:(scope.row.status=='0' && scope.row.operation_type=='1')?true:false}"
            >放样</el-button> -->
            <el-button type="text"
            v-if="scope.row.status=='4' || scope.row.status=='5'"
            @click="reportLook(scope.row.sample_inspection_id)"
            >检验结果</el-button>
            <!-- <div v-if="scope.row.s==1">
               <el-button type="text" icon="el-icon-view"
                v-hasPermi="{v:['fuhe:option'],isF:(scope.row.status=='1')}"
                @click="c(scope.row)">复核确认</el-button>
                <el-button type="text" icon="el-icon-view"
                @click="q(scope.row.id,scope.$index)"
                v-hasPermi="{v:['quyang:option'],isF:(scope.row.status=='0'&& scope.row.operation_type=='2')?true:false}"
                >取样</el-button>
                <el-button type="text" icon="el-icon-view"
                @click="f(scope.row.id)"
                v-hasPermi="{v:['fangyang:option'],isF:(scope.row.status=='0' && scope.row.operation_type=='1')?true:false}"
                >放样</el-button>
            </div>
            <div v-else>
               <el-button type="text" icon="el-icon-view"
                v-hasPermi="{v:['fuhe:option'],isF:(scope.row.status=='1')}"
                @click="c(scope.row)">复核确认</el-button>
               <el-button type="text" icon="el-icon-view"
                @click="f(scope.row.id)"
                v-hasPermi="{v:['fangyang:option'],isF:(scope.row.status=='0' && scope.row.operation_type=='1')?true:false}"
                >放样</el-button>
                 <el-button type="text" icon="el-icon-view"
                @click="q(scope.row.id,scope.$index)"
                v-hasPermi="{v:['quyang:option'],isF:(scope.row.status=='0'&& scope.row.operation_type=='2')?true:false}"
                >取样</el-button>
            </div> -->
            <div v-if="scope.$index === 0">
               <el-button type="text"
                v-if="((scope.row.status=='1')&&(data.plan.status==0||data.plan.status==1))&&(data.plan.instrument!=null)"
                :disabled="isD"
                @click="c(scope.row)">复核确认</el-button>
                <el-button type="text"
                @click="q(scope.row.id,scope.$index)"
                v-if="((scope.row.status=='0'&& scope.row.operation_type=='2')&&(data.plan.status==0||data.plan.status==1)&&(tableData[scope.$index-1].surplus_num!=0))&&isMember==true"
                >取样</el-button>
                <el-button type="text"
                @click="f(scope.row.id,scope.row.operation_num)"
                v-if="((scope.row.status=='0' && scope.row.operation_type=='1')&&(data.plan.status==0||data.plan.status==1))&&isMember==true"
                >放样</el-button>
            </div>
            <div v-else>
               <div v-if="scope.row.s==1">
               <el-button type="text"
                v-if="((scope.row.status=='1')&&(data.plan.status==0||data.plan.status==1))&&(data.plan.instrument!=null)"
                :disabled="isD"
                @click="c(scope.row)">复核确认</el-button>
                 <el-button type="text"
                v-if="(scope.row.status=='3' && scope.row.operation_type=='2'&&scope.row.repeat_operation==2)&&(data.plan.status==0||data.plan.status==1)"
                :disabled="isD"
                @click="c(scope.row)">复核确认</el-button>
                <!-- tableData[scope.$index-1].surplus_num!=0 -->
                <el-button type="text"
                @click="q(scope.row.id,scope.$index,scope.row)"
                v-if="((scope.row.status=='0'&& scope.row.operation_type=='2')&&(data.plan.status==0||data.plan.status==1)&&(handlCom(tableData,scope.$index-1)))&&isMember==true"
                >取样</el-button>
                <el-button type="text"
                @click="f(scope.row.id)"
                v-if="((scope.row.status=='0' && scope.row.operation_type=='1')&&(data.plan.status==0||data.plan.status==1))&&isMember==true"
                >放样</el-button>
                 <el-button type="text"
                @click="q(scope.row.id,scope.$index,scope.row)"
                v-if="((scope.row.status=='3' && scope.row.operation_type=='2'&&scope.row.repeat_operation==1)&&(data.plan.status==0||data.plan.status==1)&&scope.row.surplus_num!=0)&&isMember==true"
                >再次取样</el-button>
              </div>
              <!-- <div v-else>
                <el-button type="text" icon="el-icon-view"
                  v-hasPermi="{v:['fuhe:option'],isF:(scope.row.status=='1')}"
                  @click="c(scope.row)">复核确认</el-button>
                <el-button type="text" icon="el-icon-view"
                  @click="f(scope.row.id)"
                  v-hasPermi="{v:['fangyang:option'],isF:(scope.row.status=='0' && scope.row.operation_type=='1')?true:false}"
                  >放样</el-button>
                  <el-button type="text" icon="el-icon-view"
                  @click="q(scope.row.id,scope.$index)"
                  v-hasPermi="{v:['quyang:option'],isF:(scope.row.status=='0'&& scope.row.operation_type=='2')?true:false}"
                  >取样</el-button>
              </div>  -->
            </div>

          </template>
        </el-table-column>

      </el-table>
      <item-title title="操作日志"/>
      <div class="tt">
        <OptionLog v-if="data.plan.id" :Id="data.plan.id" ref="log"></OptionLog>
        <!-- <el-table :data="history" style="width: 100%"  size="medium" :show-header='false'>
        <el-table-column prop="user_name"  width="200px">
          <template slot-scope="scope">
            <span>{{scope.row.user_name}}({{scope.row.department_name}})</span>
          </template>
        </el-table-column> -->
        <!-- <el-table-column prop="department_name"  width="200px"></el-table-column> -->
        <!-- <el-table-column prop="operation_time" width="200px"></el-table-column>
        <el-table-column prop="content" >
          <template slot-scope="scope">
            <span v-if="scope.row.data==''">{{scope.row.operation_content}}</span>
            <span v-else>更换考察设备由<a style="color:#1890ff">{{scope.row.a}}</a>更换为<a style="color:#1890ff">{{scope.row.b}}</a></span>
          </template>
        </el-table-column>
      </el-table> -->
      </div>
    </div>
    <el-dialog title="查看结果" :visible.sync="openReport" width="600px" append-to-body
      :close-on-click-modal="false" v-if="openReport">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="检验结论:" prop="inspection_conclusion">
            <span v-if="inspection_conclusion==1">合格</span>
            <span v-if="inspection_conclusion==2">不合格</span>
            <span v-if="inspection_conclusion==3">无结论</span>
        </el-form-item>
        <el-form-item label-width="30px">
          <!-- <file-preview :file-list="fileList" :fileBtnOption="['preview']" /> -->
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button plain size="small" @click="openReport = false">取 消
        </el-button>
      </div>
    </el-dialog>
    <el-dialog title="更换考察设备" :visible.sync="open" append-to-body
      :destroy-on-close="true" :before-close="handleClose">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="变更前设备" prop="num2">
              <el-select style="width:100%" v-model="form.num2" placeholder="变更前设备" clearable disabled
                size="small">
                <el-option v-for="(item, index) in o" :key="index" :label="item.instrument_no+'   '+item.instrument_name"
                  :value="item.instrument_id" />
              </el-select>
            </el-form-item>
        <el-form-item label="变更原因" prop="reason">
          <el-input
            v-model="form.reason"
            type="textarea"
            placeholder="请输入变更原因"
          ></el-input>
        </el-form-item>
        <el-form-item label="变更后设备" prop="num1">
            <el-select style="width:100%" v-model="form.num1" filterable placeholder="变更后设备" clearable @change="qualityh()"
            size="small">
            <el-option v-for="(item, index) in values" :key="index" :label="item.instrument_no+'   '+item.instrument_name"
                :value="item.instrument_id" :disabled="item.instrument_id==form.num2" />
            </el-select>
        </el-form-item>
        <el-form-item label="附件：" prop="file2">
            <upload-select ref="upload2" :edit-list="filelist2" :project-data="{project_id: 'require',validation: 1}"  @selectSuccess="selectSuccess2" @uploadSuccess="uploadSuccess" @deleteSuccess="deleteSuccess" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button plain @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="gSubmitForm">提交</el-button>
      </div>
    </el-dialog>

    <el-dialog title="取样" :visible.sync="openQ" width="500px" append-to-body
      :destroy-on-close="true" :before-close="handleClose">
      <el-form ref="qform" :model="qform" :rules="qrules" label-width="80px">
        <el-form-item label="取样量" prop="qnum">
          <el-input v-model="qform.qnum" placeholder="请输入取样量" oninput="if(isNaN(value)) { value = null } if(value.indexOf('.')>0){value=value.slice(0,value.indexOf('.')+3)}">
            <template slot="append">
              <span>{{data.plan.sample_info.packaging_unit}}</span>
                <!-- <span v-if="data.plan.sample_info.packaging_nu_unit!=''">{{data.plan.sample_info.packaging_nu_unit}}</span>
                <span v-else>{{data.plan.sample_info.packaging_unit}}</span> -->
            </template>
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button plain @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="qSubmitForm">提交</el-button>
      </div>
    </el-dialog>
    <el-dialog title="复核确认" :visible.sync="openC" width="700px" append-to-body
      :destroy-on-close="true" :before-close="handleClose">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item :label='label1' prop="n">
          <span>{{qnum}}{{data.plan.sample_info.packaging_unit}}</span>
          <!-- <span v-if="data.plan.sample_info.packaging_nu_unit!=''">{{qnum}}{{data.plan.sample_info.packaging_nu_unit}}</span>
          <span v-else>{{qnum}}{{data.plan.sample_info.packaging_unit}}</span> -->
        </el-form-item>
        <el-form-item :label="label2" prop="time">
         <span>{{time}}</span>
        </el-form-item>
        <el-form-item :label="label3" prop="person">
          <span>{{person}}</span>
        </el-form-item>
        <el-form-item label="附件：" prop="file">
            <upload-select ref="upload" :edit-list="filelist" :project-data="{project_id: 'require',validation: 1}" @selectSuccess="selectSuccess" @uploadSuccess="uploadSuccess" @deleteSuccess="deleteSuccess" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button plain @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="cSubmitForm">提交</el-button>
      </div>
    </el-dialog>
    <el-dialog title="放样" :visible.sync="openF" width="800px" append-to-body
      :destroy-on-close="true" :before-close="handleClose">
      <el-form ref="form" :model="form" :rules="rules" label-width="180px">
        <!-- <el-row>
          <el-col :span='12'>
            <el-form-item label="稳定性箱编号" prop="num">
              <el-select style="width:100%" v-model="form.num" filterable placeholder="稳定性箱编号" clearable @change="qualityfh()"
                size="small">
                <el-option v-for="(item, index) in valuesd" :key="index" :label="item.instrument_no+'   '+item.instrument_name"
                :value="item.instrument_id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span='12'>
            <el-form-item label="放样量" prop="fnum">
              <el-input v-model="form.fnum" placeholder="请输入放样量">
                <template slot="append">
                   <span v-if="data.plan.sample_info.packaging_nu_unit!=''">{{data.plan.sample_info.packaging_nu_unit}}</span>
                   <span v-else>{{data.plan.sample_info.packaging_unit}}</span>
                </template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row> -->
         <el-form-item label="选择是否使用稳定性箱" prop="check">
            <el-radio v-model="radio1" label="1">是</el-radio>
            <el-radio v-model="radio1" label="0">否</el-radio>
        </el-form-item>
        <el-form-item label="稳定性箱编号" prop="num" v-if="radio1=='1'">
              <el-select style="width:100%" v-model="form.num" filterable placeholder="稳定性箱编号" clearable @change="qualityfh()"
                size="small">
                <el-option v-for="(item, index) in valuesd" :key="index" :label="item.instrument_no+'   '+item.instrument_name"
                :value="item.instrument_id" />
              </el-select>
        </el-form-item>
         <el-form-item label="稳定性箱名称" prop="wname"  v-if="radio1=='0'">
              <el-input v-model="form.wname" placeholder="请输入稳定性箱名称">
              </el-input>
        </el-form-item>
             <el-form-item label="放样复核人" prop="inspector" v-if="radio1=='0'">
              <el-select style="width:100%" v-model="form.inspector" filterable placeholder="放样复核人" clearable
                size="small">
                <el-option v-for="(item, index) in inspector" :key="index" :label="item.name"
                :value="item.id" />
              </el-select>
            </el-form-item>
        <el-form-item label="放样量" prop="fnum">
              <el-input v-model="form.fnum" disabled placeholder="请输入放样量">
                <template slot="append">
                  <span>{{data.plan.sample_info.packaging_unit}}</span>
                   <!-- <span v-if="data.plan.sample_info.packaging_nu_unit!=''">{{data.plan.sample_info.packaging_nu_unit}}</span>
                   <span v-else>{{data.plan.sample_info.packaging_unit}}</span> -->
                </template>
              </el-input>
        </el-form-item>
        <!-- <el-row>
          <el-col :span='14'>
            <el-form-item label="放样批号" prop="pnum">
              <div
                v-for="(item, index) in form.ph"
                :key="index"
              >
                  <el-form-item
                    label-width="0"
                    :prop="'ph.' + index + '.pnum'"
                    :rules="[
                      {
                        required: true,
                        message: '批号不能为空',
                        trigger: 'blur',
                      },
                    ]"
                  >
                   <el-row>
                      <el-col :span='20'>
                         <el-input
                         style="width:260px"
                            v-model="item.pnum"
                            placeholder="输入批号"
                          ></el-input>
                      </el-col>
                      <el-col :span='4'>
                           <el-button
                          icon="el-icon-plus"
                          type="text"
                          v-if="index == 0"
                          @click="addInputItem"
                          >添加
                        </el-button>
                        <el-button
                          class="text-btn-red"
                          icon="el-icon-delete"
                          type="text"
                          v-if="index != 0"
                          @click="deleteInputItem(index)"
                          >删除
                        </el-button>
                      </el-col>
                    </el-row>


                  </el-form-item>
              </div>
            </el-form-item>
          </el-col>
           <el-col :span='10'>

          </el-col>
        </el-row> -->
        <!-- <el-form-item label="是否为直接接触包材" prop="check">
            <el-radio v-model="radio" label="1">是</el-radio>
            <el-radio v-model="radio" label="0">否</el-radio>
        </el-form-item> -->
        <el-form-item label="直接接触包材" prop="nmaterial">
          <el-radio-group v-model="checkListR" @change="ch()">
            <span v-for="(item,index) in v1" :key=index style="margin-right:10px">
               <el-radio :label="item.id">{{item.packing_material_name}}</el-radio>
            </span>
          </el-radio-group>
            <!-- <el-checkbox-group v-model="checkList">
              <span v-for="(item,index) in v1" :key=index >
                <el-checkbox :label="item" style="width:100px">{{item.packing_material_name}}</el-checkbox>
              </span>
            </el-checkbox-group> -->
        </el-form-item>
        <el-form-item label="直接接触包材封口形式" prop="inum">
          <el-select style="width:100%" v-model="form.inum" placeholder="直接接触包材封口形式" clearable multiple
                size="small" @change="selectInum">
                <el-option v-for="(item, index) in values1" :key="index" :label="item.sealing_name"
                  :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="辅助措施" prop="cnum">
          <el-select style="width:100%" v-model="form.cnum" placeholder="辅助措施" clearable
                size="small" @change="selectCnum">
            <el-option v-for="(item, index) in values3" :key="index" :label="item.secondary_measure_name"
              :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否有非直接接触包材" prop="check">
            <el-radio v-model="radio" label="1">是</el-radio>
            <el-radio v-model="radio" label="0">否</el-radio>
        </el-form-item>
        <el-form-item label="非直接接触包材" prop="wmaterial" v-if="radio=='1'">
          <div>
            <el-checkbox-group v-model="checkList1">
              <span v-for="(item,index) in v2" :key=index >
                <el-checkbox :label="item" style="width:100px">{{item.packing_material_name}}</el-checkbox>
              </span>
            </el-checkbox-group>
          </div>
        </el-form-item>
        <el-form-item label="非直接接触包材封口形式" prop="onum" v-if="radio=='1'">
           <el-select style="width:100%" v-model="form.onum" placeholder="非直接接触包材封口形式" clearable multiple
                size="small" @change="selectOnum">
                <el-option v-for="(item, index) in values2" :key="index" :label="item.sealing_name"
                  :value="item.id" />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="辅助措施" prop="cnum"  v-if="radio=='1'">
          <el-select style="width:100%" v-model="form.cnum" placeholder="辅助措施" clearable
                size="small" @change="selectCnum">
            <el-option v-for="(item, index) in values3" :key="index" :label="item.secondary_measure_name"
              :value="item.id" />
          </el-select>
        </el-form-item> -->
         <el-form-item label="附件：" prop="file1">
            <upload-select ref="upload1" :edit-list="filelist1" :project-data="{project_id: 'require',validation: 1}"  @selectSuccess="selectSuccess1" @uploadSuccess="uploadSuccess" @deleteSuccess="deleteSuccess" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button plain @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="submitForm">提交</el-button>
      </div>
    </el-dialog>
    <el-dialog title="详情" :visible.sync="openDetail" width="1000px" append-to-body
      :destroy-on-close="true" :before-close="handleClose">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" :label-position="left">
        <el-row>
          <el-col :span='12'>
            <el-form-item label='样品名称：'>
              <span>{{data.plan.sample_info.sample_name}}</span>
            </el-form-item>
          </el-col>
          <el-col :span='12'>
             <el-form-item label='放置条件：'>
              <span>{{data.plan.place_conditions.place_conditions_name}}</span>
            </el-form-item>
          </el-col>
          <el-col :span='12'>
             <el-form-item label='批号：'>
              <div style="display: flex;flex-wrap: wrap;">
                 <div v-for="(item,index) in data.plan.batch_info" :key=index>
                  <span>{{item.sample_batch}}</span>
                  <span v-if="data.plan.batch_info.length-1!=index">,</span>
                </div>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span='12'>
             <el-form-item label='考察点：'>
              <span v-if="(detail.sample_point_num=='0'&&detail.sample_point_unit=='0')&&(detail.operation_type=='1')">-</span>
             <span v-else>
               <span>{{detail.sample_point_num}}</span><span v-if="detail.sample_point_unit=='1'">天</span><span v-if="detail.sample_point_unit=='2'">月</span>
             </span>
            </el-form-item>
          </el-col>
          <el-col :span='12' v-if="detail.operation_type=='2'">
             <el-form-item label='应取样日期：'>
              <span v-if="detail.operation_time!=''">{{ dateFormat1('yyyy-mm-dd',detail.operation_time) }}</span>
            </el-form-item>
          </el-col>
          <el-col :span='12' v-if="detail.operation_type=='1'">
             <el-form-item label='应放样日期：'>
              <span v-if="detail.operation_time!=''">{{ dateFormat1('yyyy-mm-dd',detail.operation_time) }}</span>
            </el-form-item>
          </el-col>
          <el-col :span='12' v-if="detail.operation_type=='2'">
             <el-form-item label='最迟取样日期：'>
              <span v-if="detail.last_operation_time!=''">{{ dateFormat1('yyyy-mm-dd',detail.last_operation_time) }}</span>
            </el-form-item>
          </el-col>
          <el-col :span='12' v-if="detail.operation_type=='1'">
             <el-form-item label='最迟放样日期：'>
             <span v-if="detail.last_operation_time!=''">{{ dateFormat1('yyyy-mm-dd',detail.last_operation_time) }}</span>
            </el-form-item>
          </el-col>
          <el-col :span='12' v-if="detail.operation_type=='1'">
             <el-form-item label='实际放样日期：'>
              <span v-if="detail.operation_record!=null">{{ dateFormat1('yyyy-mm-dd',detail.operation_record[0].act_opera_time) }}</span>
            </el-form-item>
          </el-col>
          <el-col :span='12' v-if="detail.operation_type=='2'&&detail.operation_record!=null">
             <el-form-item label='实际取样日期：'>
              <span v-if="detail.operation_record!=null">{{ dateFormat1('yyyy-mm-dd',detail.operation_record[0].act_opera_time) }}</span>
            </el-form-item>
          </el-col>
          <el-col :span='12' v-if="detail.operation_type=='1'">
             <el-form-item label='放样量：'>
              <span>{{detail.operation_num}}{{data.plan.sample_info.packaging_unit}}</span>
              <!-- <span v-if="data.plan.sample_info.packaging_nu_unit!=''">{{detail.operation_num}}{{data.plan.sample_info.packaging_nu_unit}}</span>
              <span v-else>{{detail.operation_num}}{{data.plan.sample_info.packaging_unit}}</span> -->
            </el-form-item>
          </el-col>
          <el-col :span='12' v-if="detail.operation_type=='2'">
             <el-form-item label='取样量：'>
               <span>{{detail.operation_num}}{{data.plan.sample_info.packaging_unit}}</span>
              <!-- <span v-if="data.plan.sample_info.packaging_nu_unit!=''">{{detail.operation_num}}{{data.plan.sample_info.packaging_nu_unit}}</span>
              <span v-else>{{detail.operation_num}}{{data.plan.sample_info.packaging_unit}}</span> -->
            </el-form-item>
          </el-col>
          <el-col :span='12'>
             <el-form-item label='剩余量：'>
               <span>{{detail.surplus_num}}{{data.plan.sample_info.packaging_unit}}</span>
              <!-- <span v-if="data.plan.sample_info.packaging_nu_unit!=''">{{detail.surplus_num}}{{data.plan.sample_info.packaging_nu_unit}}</span>
              <span v-else>{{detail.surplus_num}}{{data.plan.sample_info.packaging_unit}}</span> -->
            </el-form-item>
          </el-col>
          <el-col :span='12'>
             <el-form-item label='状态：'>
              <span v-if="detail.status=='0'&&detail.operation_type=='1'">未放样</span>
              <span v-if="detail.status=='0'&&detail.operation_type=='2'">未取样</span>
              <span v-if="detail.status=='1'">待复核</span>
              <span v-if="detail.status=='2'">已放样</span>
              <span v-if="detail.status=='3'">检验中</span>
              <span v-if="detail.status=='4'">已检验</span>
              <span v-if="detail.status=='5'">已结束</span>
              <span v-if="detail.status=='6'">已取消</span>
            </el-form-item>
          </el-col>
          <!-- <el-col :span='12' v-if="detail.operation_type=='1'">
             <el-form-item label='放样操作人：'>
              <span>{{detail.operation_user_name}}</span>
            </el-form-item>
          </el-col>
          <el-col :span='12' v-if="detail.operation_type=='2'">
             <el-form-item label='取样操作人：'>
              <span>{{detail.operation_user_name}}</span>
            </el-form-item>
          </el-col> -->
          <!-- <el-col :span='12'>
             <el-form-item label='操作时间：'>
              <span>{{detail.operation_time}}</span>
            </el-form-item>
          </el-col> -->
          <!-- <el-col :span='12'>
             <el-form-item label='复核人：'>
              <span v-if="data.plan.instrument">{{data.plan.instrument.locker_name}}</span>
            </el-form-item>
          </el-col>
          <el-col :span='12'>
             <el-form-item label='复核时间：'>
              <span>{{detail.check_time}}</span>
            </el-form-item>
          </el-col> -->
        </el-row>
         <el-table :data="detail.operation_record" size="medium" border>
             <el-table-column prop="plan_no" label="操作类型" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.operation_type==1">复核</span>
                <span v-if="scope.row.operation_type==0&&detail.operation_type=='1'">放样</span>
                <span v-if="scope.row.operation_type==0&&detail.operation_type=='2'">取样</span>
              </template>
            </el-table-column>
            <el-table-column prop="plan_no" label="操作人" align="center">
              <template slot-scope="scope">
                {{scope.row.operation_user_name}}
              </template>
            </el-table-column>
             <el-table-column prop="plan_no" label="数量" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.operation_num!=0">{{scope.row.operation_num}}</span>
                <span v-if="scope.row.operation_num==0">/</span>
              </template>
            </el-table-column>
            <el-table-column prop="sample_name" label="操作时间" align="center">
              <template slot-scope="scope">
                {{scope.row.act_opera_time}}
              </template>
            </el-table-column>
            <!-- <el-table-column prop="sample_name" label="取样量" align="center">
              <template slot-scope="scope">
                {{scope.row.operation_num}}
              </template>
            </el-table-column> -->
            <el-table-column prop="sample_name" label="附件" align="center">
              <template slot-scope="scope" v-if="scope.row.enclosure!=null">
                <div class='ps'>
                   <file-preview :file-list="scope.row.enclosure" :fileBtnOption="['preview']" />
                </div>
                <!-- {{scope.row.enclosure}} -->
              </template>
            </el-table-column>
          </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button plain @click="handleClose">取 消</el-button>
      </div>
    </el-dialog>
    <reportdialog  ref="reportdialog"  :formOpen="formOpen" :rowList="rowList"/>
  </div>
</template>

<script>
import { detail,measureList,materialList,sealingList,putSample,getSample,check,changeInstrument,history,oldList,changeCreate,reportView,Instrument,instrumentD,member} from "@/api/stability/management";
import {
  instrument
} from "@/api/stability/giveUp";
import {
  applyHeader,
  sampleListTable
} from "@/api/sampleInspection";
import Item from '@/layout/components/Sidebar/Item.vue';
import OptionLog from '@/views/stability/management/details/optionLog.vue';
import reportdialog from '@/views/sampleInspection/modules/reportList.vue';
export default {
  components: {
    OptionLog,
    reportdialog
  },
  data() {
      let nmaterial = (rule, value, callback) => {
        if (this.checkListR!='') {
        callback();
      } else {
        callback(new Error("请选择一个直接接触包材"));
      }
      // if (this.checkList.length > 0) {
      //   if(this.checkList.length>1){
      //     this.checkList.splice(0,1)
      //   }
      //   callback();
      // } else {
      //   callback(new Error("请选择一个直接接触包材"));
      // }
    };
     let wmaterial = (rule, value, callback) => {
      if (this.checkList1.length > 0) {
        callback();
      } else {
        callback(new Error("请至少选择一个非直接接触包材"));
      }
    };
    let pnum = (rule, value, callback) => {
      if (this.form.ph.length > 0) {
        callback();
      } else {
        callback(new Error("请至少添加一个批号,最多添加五个批号"));
      }
    };
    let fnum = (rule, value, callback) => {
        const r = /^\+?[1-9][0-9]*$/; // 正整数
        if (value === "") {
          callback(new Error("放样量不能为空"));
         } else {
          callback();
        }
        // else if (!r.test(value)) {
        //   callback(new Error("放样量必须为正整数"));
        // }

      };
    let qnum = (rule, value, callback) => {
        let r = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/; // 正整数
        if (value === "") {
          callback(new Error("取样量不能为空"));
        } else {
           if (r.test(value)) {
             if(Number(value)>this.surplus){
                callback(new Error("取样量应小于等于剩余量"));
              }else{
                callback();
              }
          } else {
            callback(new Error("请输入正数,可包含两位小数"));
          }
          // callback();
        }
        //  else if(Number(value)>this.surplus){
        //   callback(new Error("取样量应小于等于剩余量"));
        // }

        // else if (!r.test(value)) {
        //   callback(new Error("取样量必须为正整数"));
        // }
        // else if(Number(value)>this.surplus){
        //   callback(new Error("取样量应小于等于剩余量"));
        // }else {
        //   callback();
        // }
      };
     var filePass = (rule, value, callback) => {
      if (this.objData.fileList.length > 0 || this.objData.newFileList.length > 0) {
          callback()
        } else {
          callback(new Error('请上传附件'))
        }
    }
     var filePass1 = (rule, value, callback) => {
      if (this.objData1.fileList.length > 0 || this.objData1.newFileList.length > 0) {
          callback()
        } else {
          callback(new Error('请上传附件'))
        }
    }
    var filePass2 = (rule, value, callback) => {
      if (this.objData2.fileList.length > 0 || this.objData2.newFileList.length > 0) {
          callback()
        } else {
          callback(new Error('请上传附件'))
        }
    }
    return {
      isMember:false,
      member:[],
      checkListR:'',
      rowList:{},
      formOpen:{
       tableResults: {
          id: '',
          report: [],//
          computation_sheet: [], //计算表格
          inspection_map: []//  检验图谱
        },
        relation_plan_id: ''
      },
      isD:false,
      fileList: [],
      openReport:false,
      label1:'放样量',
      label2:'放样时间',
      label3:'放样人',
      qnum:'',
      time:'',
      person:'',
      radio:'0',
      radio1:'1',
      left: "left",
      tableData: [

      ],
      history:[],
      open: false,
      openQ: false,
      openC: false,
      openF: false,
      values: [
        {
          instrument_id:'1',
          instrument_name:'宝箱1',
          instrument_no:'1',
          brand_model:'1',
          attrs:'1',
          locker_id:'1',
          locker_name:'cdd'
        },
        {
          instrument_id:'2',
          instrument_name:'宝箱2',
          instrument_no:'2',
          brand_model:'1',
          attrs:'1',
          locker_id:'1',
          locker_name:'cdd1'
        },
      ],
      valuesd:[],
      values1: [],
      values2: [],
      values3: [],
      checkList: [],
      checkList1: [],
      form: {
        suggestion:'',
        reason: "",
        key: "",
        qnum:'',
        num: "",
        num1:'',
        num2:'',
        fnum: "",
        inum:[],
        onum:[],
        cnum:'',
        inspector:'',
        wname:'',
        ph:[
          {
          pnum:''
          }
        ]
      },
      qform:{
        num:''
      },
      qrules: {
        qnum: [
          { required: true, validator: qnum },
         ],
      },
      rules: {
        num: [
          { required: true, message: "稳定性箱编号不能为空", trigger: "change" },
         ],
        qnum: [
          { required: true, validator: qnum },
         ],
         num2: [
          { required: true, message: "变更前设备不能为空", trigger: "change" },
         ],
         num1: [
          { required: true, message: "变更后设备不能为空", trigger: "change" },
         ],
         fnum: [
          { required: true, validator: fnum },
         ],
         pnum: [
          { required: true, validator: pnum },
         ],
         nmaterial: [
          { required: true,validator: nmaterial },
          ],
          wmaterial: [
            { required: true,validator: wmaterial },
          ],
         inum: [
          { required: true, message: "直接接触包材封口形式不能为空", trigger: "change" },
         ],
         onum: [
          { required: true, message: "非直接接触包材封口形式不能为空", trigger: "change" },
         ],
         cnum: [
          { required: true, message: "辅助措施不能为空", trigger: "change" },
         ],
        reason: [
          { required: true, message: "变更原因不能为空", trigger: "blur" },
         ],
        inspector: [
          { required: true, message: "复核人不能为空", trigger: "change" },
         ],
        wname: [
          { required: true, message: "稳定性箱名称不能为空", trigger: "blur" },
         ],
         file: [
          {
            required: true,
            validator: filePass,
            trigger: 'change'
          }
        ],
        file1: [
          {
            required: true,
            validator: filePass1,
            trigger: 'change'
          }
        ],
        file2: [
          {
            required: true,
            validator: filePass2,
            trigger: 'change'
          }
        ],
      },
      rules1:{

      },
      id:'',
      v1:[],
      v2:[],
      s1:[],
      s2:[],
      data:{
        plan:{
          sample_info:{},
          inspect_type:{},
          place_conditions:{},
          instrument:{},
          in_packing:{

          },
          out_packing:{}
        }
      },
      id1:'',
      id2:'',
      surplus:'',
      id3:'',
      x:{},
      o:[],
      isShow:false,
      oldInstrument:{},
      newInstrument:{},
      plan:[],
      isS:0,
      inspection_conclusion:'',
      openDetail:false,
      detail:{

      },
      num:{},
      userId:'',
      secondary_measure_id:'',
      secondary_measure_name:'',
      stability_scheme_id:'',
      filelist:[],
      filelist1:[],
      filelist2:[],
      inspector:[],
     objData: {
          fileList: [],
          newFileList: []
        },
     objData1: {
          fileList: [],
          newFileList: []
        },
    objData2: {
          fileList: [],
          newFileList: []
        },
    }
  },
  //是计算属性，也可以理解为一个方法。
  computed: {
    handlCom(){
      return function(arr,index){
        let a = false
        for(let i = index ; i< arr.length;i--){
            if(i <= 0){
                arr[i].surplus_num !== 0 
                a = true
                break
            }
        }
        return a

      }
    }
  },
  //属性是手动定义的所需监听的值
  watch: {},
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    this.userId = this.$store.getters.userInfo.user.id
    //  console.log(this.$store.getters.userInfo.user.id)
    this.id = this.$route.query.id
    if (this.id) {
      this.getDetail(this.id)
      // this.getInstrument(this.id)
    }
    this.getMeasureList()
    this.getImaterialList()
    this.getOmaterialList()
    this.getIsealingList()
    this.getOsealingList()
    this.getinstrument()
    this.handlApplyHeader()
    this.getmember()
    // this.getinstrumentd()
    // this.getHistory()
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {},
  //是Vue实例对象上绑定的方法，供当前Vue组件作用域内使用，
  methods: {
    getmember(){
      
    },
    ch(){
      this.checkList=[]
      this.v1.forEach(item=>{
       if(this.checkListR==item.id){
         this.checkList.push(item)
       }
      })
    },
    selectSuccess(obj) {
        this.objData = obj
        if (obj.fileList.length > 0 || obj.newFileList.length > 0) {
          this.$nextTick(_ => {
            this.$refs.form.clearValidate('file')
          })
        }
      },
    selectSuccess1(obj) {
        this.objData1 = obj
        if (obj.fileList.length > 0 || obj.newFileList.length > 0) {
          this.$nextTick(_ => {
            this.$refs.form.clearValidate('file1')
          })
        }
      },
       selectSuccess2(obj) {
        this.objData2 = obj
        if (obj.fileList.length > 0 || obj.newFileList.length > 0) {
          this.$nextTick(_ => {
            this.$refs.form.clearValidate('file2')
          })
        }
      },
    //负责人
    handlApplyHeader() {
      let data = {
        code: "Checker"
      };
      applyHeader(data).then(res => {
        if (res.code === 200) {
          this.inspector = res.data;
        }
      });
    },
    //  getinstrumentd(id){
    //    instrumentD(id).then(res=>{
    //       if(res.code==200){
    //         console.log(res.data)
    //         this.valuesd = res.data
    //       }
    //    })
    // },
    deleteSuccess() {
      // this.formData.enclosure = this.$refs.upload.emitFileList()
    },
    // 附件上传成功
    uploadSuccess(file) {
      // this.formData.enclosure = this.$refs.upload.emitFileList()
    },
    getinstrument(){
      let data = {
        subTypes: [],
        key: ''
      }
       instrument(data).then(res=>{
          if(res.code==200){
            console.log(res.data)
            this.values = res.data
          }
       })
    },
    // getInstrument(id){
    //   Instrument(id).then(res=>{
    //     if(res.code==200){
    //       console.log(res.data)
    //     }
    //   })
    // },
    cellStyle(data) {
      return "cursor:pointer;"
    },
    rowClick(row, column){
      console.log(row)
      if (column.label == "操作") return;
      this.openDetail= true
      this.detail=row
    },
     reportLook(id) {
        // this.$refs.reportdialog.openport()
        let row = {}
        reportView(id).then(res=>{
          if(res.code === 200){
            row = res.data
            this.rowList = row
            this.formOpen.tableResults = {
              computation_sheet: [],
              report: [],
              inspection_map: []
            }
            if (row.computation_sheet && row.inspection_result && row.inspection_map) {
              this.formOpen.tableResults.computation_sheet = JSON.parse(JSON.stringify(row.computation_sheet)) || []
              this.formOpen.tableResults.report = JSON.parse(JSON.stringify(row.inspection_result)) || []
              this.formOpen.tableResults.inspection_map = row.inspection_map || []
              for (let i = 0; i < this.formOpen.tableResults.report.length; i++) {
                this.formOpen.tableResults.report[i].boole = true
                if (row.experiment_table_info_map) {
                  this.formOpen.tableResults.report[i].ruleForm = row.experiment_table_info_map[this.formOpen.tableResults.report[i].batch_no]
                  this.$refs.reportdialog.openport()
                } else {
                  if (row.inspection_type === 'inspection_type_wd') {
                    sampleListTable({ id: row.relation_plan_id }).then(res => {
                      if (res.code === 200) {
                        this.formOpen.tableResults.report.forEach(item => {
                          if (res.data[item.batch_no]) {
                            item.ruleForm = res.data[item.batch_no]
                          }
                        })
                      }
                    })
                  }
                }
              }
            }
            this.activeNames = this.formOpen.tableResults.report[0].batch_no
          }
        })

      },

    // reportLook(id){
    //   this.openReport = true
    //   reportView(id).then(res=>{
    //     if(res.code==200){
    //       console.log(res.data)
    //       this.inspection_conclusion = res.data.inspection_conclusion
    //       this.fileList = res.data.inspection_result
    //     }
    //   })
    // },
    qualityh(){
      this.values.forEach(item=>{
        if(this.form.num1==item.instrument_id){
          this.newInstrument = {
            instrument_id:item.instrument_id,
            instrument_name:item.instrument_name,
            instrument_no:item.instrument_no,
            brand_model:item.brand_model,
            attrs:item.attrs,
            locker_id:item.locker_id,
            locker_name:item.locker_name
          }
        }
      })
      this.o.forEach(item=>{
        if(this.form.num2==item.instrument_id){
          this.oldInstrument = {
            instrument_id:item.instrument_id,
            instrument_name:item.instrument_name,
            instrument_no:item.instrument_no,
            brand_model:item.brand_model,
            attrs:item.attrs,
            locker_id:item.locker_id,
            locker_name:item.locker_name
          }
        }
      })
    },
     qualityfh(){
      this.valuesd.forEach(item=>{
        if(this.form.num==item.instrument_id){
          this.num = {
            instrument_id:item.instrument_id,
            instrument_name:item.instrument_name,
            instrument_no:item.instrument_no,
            brand_model:item.brand_model,
            attrs:item.attrs,
            locker_id:item.locker_id,
            locker_name:item.locker_name
          }
        }
      })
    },
    selectInum(){
    this.s1=[]
     console.log(this.form.inum,this.values1)
     this.form.inum.forEach(item=>{
       this.values1.forEach(itm=>{
          if(item ==itm.id){
            let obj = {
              in_packing_material_id:itm.id,
              in_packing_material:itm.sealing_name
            }
            this.s1.push(obj)
          }
       })
     })
    },
    selectOnum(){
     this.s2=[]
     this.form.onum.forEach(item=>{
       this.values2.forEach(itm=>{
          if(item ==itm.id){
            let obj = {
              out_packing_material_id:itm.id,
              out_packing_material:itm.sealing_name
            }
            this.s2.push(obj)
          }
       })
     })
    },
    selectCnum(){
      this.values3.forEach(itm=>{
          if(this.form.cnum ==itm.id){
            this.secondary_measure_id=itm.id
            this.secondary_measure_name=itm.secondary_measure_name
          }
       })
    },
    getMeasureList(){
       measureList().then(res=>{
        if(res.code==200){
          this.values3 = res.data
        }
       })
    },
    getImaterialList(){
      materialList(1).then(res=>{
        if(res.code==200){
          console.log(res.data)
          this.v1 = res.data
        }
      })
    },
    getOmaterialList(){
      materialList(2).then(res=>{
        if(res.code==200){
          console.log(res.data)
          this.v2 = res.data
        }
      })
    },
    getIsealingList(){
       sealingList(1).then(res=>{
         if(res.code==200){
           console.log(res.data)
          this.values1 = res.data
        }
       })
    },
    getOsealingList(){
       sealingList(2).then(res=>{
         if(res.code==200){
           console.log(res.data)
          this.values2 = res.data
        }
       })
    },
    addInputItem() {
      if(this.form.ph.length>4){
        this.$message.error('最多添加五个批号')
      }else{
       this.form.ph.push({
        pnum:''
      });
      }
    },
    deleteInputItem(index) {
      this.form.ph.splice(index, 1);
    },
    getDetail(id){
      detail(id).then(res=>{
        if(res.code==200){
          console.log(res.data)
          this.data = res.data
          member(this.data.plan.id).then(res=>{
            if(res.code==200){
              this.member = res.data

              if(this.member.indexOf(this.userId)>-1){
                this.isMember = true
              }else{
                this.isMember = false
              }
            }
          }) 

          this.stability_scheme_id = res.data.plan.stability_scheme_id
          if(this.data.plan.instrument){
          if(this.userId!=this.data.plan.instrument.locker_id){
             this.isD = true
          }else{
            this.isD = false
          }
        }
          this.tableData = res.data.point_info
          // this.ids = res.data.plan.stability_scheme_id
          // Instrument(res.data.plan.stability_scheme_id).then(res=>{
          //   if(res.code==200){
          //     console.log(res.data)
          //     this.values = res.data
          //   }
          // })
          // let time1 = new Date()
          let time1= this.dateFormat1('yyyy-mm-dd',new Date())
          // let time1 = new Date().getTime()
          // console.log(time1)
          let status = this.tableData[0].status
          this.tableData.forEach(item=>{
            let time= this.dateFormat1('yyyy-mm-dd',new Date(item.operation_time))
            // let time= new Date(item.operation_time).getTime()
            if(time1>=time&&status==2){
              Object.assign(item,{s:1})
            }else{
               Object.assign(item,{s:0})
            }
          })
          if(this.tableData[0].status!=0){
            this.isShow = true
          }else{
            this.isShow = false
          }
          if(res.data.plan.instrument!=null){
            this.form.num2 = res.data.plan.instrument.instrument_id
            this.o.push(res.data.plan.instrument)
          }
          // history(this.data.plan.id).then(res=>{
          //     if(res.code==200){
          //       console.log(res.data)
          //       this.history = res.data.data
          //       this.history.forEach(item=>{
          //         if(item.data!=''){
          //           let data = JSON.parse(item.data)
          //           console.log(data)
          //           Object.assign(item,{a:data.old.instrument_name})
          //           Object.assign(item,{b:data.new.instrument_name})
          //         }
          //       })
          //     }
          //   })
        }
      })
    },
    q(id,index,row) {
      console.log(id,index,row,'--------------')
      this.openQ = true;
      this.id2 = id
      if((row.status=='3'&&row.operation_type=='2'&&row.repeat_operation==1)&&(this.data.plan.status==0||this.data.plan.status==1)){
           this.surplus = row.surplus_num
      }else{
         for(let i=index-1;i<index;i--){
          if(this.tableData[i].surplus_num!=0){
            this.surplus = this.tableData[i].surplus_num
            break
          }
        }
      }
      // let inx = index-1
      // for(let i=index-1;i<index;i--){
      //   if(this.tableData[i].surplus_num!=0){
      //      this.surplus = this.tableData[i].surplus_num
      //      break
      //   }
      // }
      // this.surplus = this.tableData[index-1].surplus_num
    },
    f(id,operation_num) {
      this.openF = true;
      this.form.fnum = operation_num
      this.id1 = id
      let data={
        key:this.form.num
      }
      instrumentD(data).then(res=>{
          if(res.code==200){
            console.log(res.data)
            this.valuesd = res.data
          }
       })
    },
    c(row){
      console.log(row)
      if(row.operation_type==1){
        this.label1 = '放样量'
        this.label2 = '放样时间'
        this.label3 = '放样人'
      }else{
        this.label1 = '取样量'
        this.label2 = '取样时间'
        this.label3 = '取样人'
      }
      this.openC = true
      this.id3 = row.id
      if(row.operation_type==1 && row.operation_record!=null){
          this.qnum = row.operation_record[0].operation_num
          this.time = this.dateFormat1('yyyy-mm-dd',row.operation_record[0].act_opera_time)
          this.person =row.operation_record[0].operation_user_name
      }
       if(row.operation_type==2 && row.operation_record!=null){
          this.qnum = row.operation_record[row.operation_record.length-1].operation_num
          this.time = this.dateFormat1('yyyy-mm-dd',row.operation_record[row.operation_record.length-1].act_opera_time)
          this.person =row.operation_record[row.operation_record.length-1].operation_user_name
      }
      // this.objData={
      //     fileList: [],
      //     newFileList: []
      //   }
       this.objData.fileList=[]
       this.objData.newFileList=[]
       this.filelist=[]
      // this.qnum = row.operation_num
      // this.time = this.dateFormat1('yyyy-mm-dd',new Date(row.operation_time))
      // this.person = row.operation_user_name
    },
    //返回
    handleBack() {
      this.$route.params.refresh = true;
      this.$router.go(-1);
    },
    changeStability() {
      this.open = true;
      // oldList().then(res=>{
      //   if(res.code==200){
      //     this.o = res.data
      //   }
      // })
    },
    handleClose() {
      this.open = false;
      this.openQ = false;
      this.openC = false;
      this.openF = false;
      this.openDetail = false;
      this.form={
        suggestion:'',
        reason: "",
        key: "",
        qnum:'',
        num1:'',
        fnum: "",
        num2:'',
        inum:[],
        onum:[],
        cnum:'',
        wname:'',
        inspector:'',
        ph:[
          {
          pnum:''
          }
        ]
      }
      this.qform={
        qnum:''
      }
       this.objData.fileList=[]
        this.objData.newFileList=[]
       this.filelist=[]
      this.getDetail(this.id)
    },
    cSubmitForm(){
      this.$refs.upload.saveFile().then((dataList) => {
          this.filelist = dataList[0]
           this.$refs.form.validate((valid) => {
            if (valid) {
               let data={
                id:this.id3,
                enclosure:this.filelist
              }
              check(data).then(res=>{
                if(res.code==200){
                  this.$message.success('复核成功')
                  this.openC = false;
                  this.getDetail(this.id)
                  this.handleClose()
                }
              })
            }else{
              console.log(1111)
              // this.handleClose()
            }
           })
        })
      // check(this.id3).then(res=>{
      //   if(res.code==200){
      //     this.$message.success('复核成功')
      //     this.openC = false;
      //     this.getDetail(this.id)
      //   }
      // })
    },
    changeR(){
      console.log(this.form.key)
       this.values.forEach(item=>{
         if(this.form.key==item.instrument_id){
           this.x={
              instrument_id:item.instrument_id,
              instrument_name:item.instrument_name,
              instrument_no:item.instrument_no,
              brand_model:item.brand_model,
              attrs:item.attrs,
              locker_id:item.locker_id,
              locker_name:item.locker_name
           }
         }
       })
    },
    gSubmitForm(){
      this.plan=[]
      let obj = {
              stability_scheme_id:this.data.plan.stability_scheme_id,
              stability_scheme_name:this.data.plan.stability_scheme_name,
              project_id:this.data.plan.project_id,
              project_name:this.data.plan.project_name,
              project_no:this.data.plan.project_no,
              project_leader_id:this.data.plan.project_leader_id,
              project_leader_name:this.data.plan.project_leader_name,
              inspect_type:this.data.plan.inspect_type,
              place_conditions:this.data.plan.place_conditions,
              plan_id:this.data.plan.id,
              plan_no:this.data.plan.plan_no,
              sample_info:this.data.plan.sample_info,
              sample_batch:this.data.plan.sample_batch,
              sample_attrs:this.data.plan.sample_attrs,
              packaging_nu:this.data.plan.packaging_nu,
              packaging_nu_unit:this.data.plan.packaging_nu_unit,
              packaging_unit:this.data.plan.packaging_unit,
              producer:this.data.plan.producer
            }
      this.plan.push(obj)
       this.$refs.upload2.saveFile().then((dataList) => {
          this.filelist2 = dataList[0]
          this.$refs.form.validate((valid) => {
            if (valid) {
              let data = {
                old_instrument:this.oldInstrument,
                new_instrument:this.newInstrument,
                change_reason:this.form.reason,
                info:this.plan,
                enclosure:this.filelist2
              }
              changeCreate(data).then(res=>{
                if(res.code==200){
                  this.$message.success('已提交审批')
                  this.open = false;
                  this.handleClose()
                  this.getDetail(this.id)
                  this.$refs.log.getLogList();
                  // this.getDetail(this.id)
                }
              })
            }
          })
        })
      // this.$refs.form.validate((valid) => {
      //   if (valid) {
      //     let data = {
      //       old_instrument:this.oldInstrument,
      //       new_instrument:this.newInstrument,
      //       change_reason:this.form.reason,
      //       info:this.plan
      //     }
      //     changeCreate(data).then(res=>{
      //       if(res.code==200){
      //         this.$message.success('已提交审批')
      //         this.open = false;
      //         this.handleClose()
      //         this.getDetail(this.id)
      //         this.$refs.log.getLogList();
      //         // this.getDetail(this.id)
      //       }
      //     })
      //   }
      // })

    },
    qSubmitForm(){
      console.log(this.surplus)
     this.$refs.qform.validate((valid) => {
        if (valid) {
          let data = {
            id:this.id2,
            operation_num:Number(this.qform.qnum),
            surplus_num:Number(this.surplus)
          }
          getSample(data).then(res=>{
            if(res.code==200){
              this.$message.success('取样成功')
              this.openQ = false;
              this.handleClose()
              this.getDetail(this.id)
            }
          })
        }
     })
    },
    submitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
           let ph = []
          this.form.ph.forEach(item=>{
            ph.push(item.pnum)
          })
          let checkList = []
          this.checkList.forEach(item=>{
            let obj = {
              in_sealing_id:item.id,
              in_sealing:item.packing_material_name
            }
            checkList.push(obj)
          })
          let checkList1 = []
          this.checkList1.forEach(item=>{
            let obj1 = {
              out_sealing_id:item.id,
              out_sealing:item.packing_material_name
            }
            checkList1.push(obj1)
          })
          // if(this.radio=='0'){
          //   checkList = []
          //   this.s1 = []
          // }
          if(this.radio1!=1){
            let locker_name=''
            this.inspector.forEach(item=>{
              if(this.form.inspector==item.id){
                locker_name=item.name
              }
            })
            this.num = {
              instrument_id:'',
              instrument_name:this.form.wname,
              instrument_no:'',
              brand_model:'',
              attrs:'',
              locker_id:this.form.inspector,
              locker_name:locker_name
            }
          }
         this.$refs.upload1.saveFile().then((dataList) => {
          this.filelist1 = dataList[0]
          let data = {
            id:this.data.plan.id,
            put_sample_id:this.id1,
            batch_no:ph,
            instrument:this.num,
            // instrument:{
            //   instrument_id:this.form.num.instrument_id,
            //   instrument_name:this.form.num.instrument_name,
            //   instrument_no:this.form.num.instrument_no,
            //   brand_model:this.form.num.brand_model,
            //   attrs:this.form.num.attrs,
            //   locker_id:this.form.num.locker_id,
            //   locker_name:this.form.num.locker_name
            // },
            operation_num:Number(this.form.fnum),
            if_packing:Number(this.radio),
            in_packing:{
              in_sealing_ary:checkList,
              in_packing_material_ary:this.s1
            },
            out_packing:{
              out_sealing_ary:checkList1,
              out_packing_material_ary:this.s2
            },
            secondary_measure_id:this.secondary_measure_id,
            secondary_measure_name:this.secondary_measure_name,
            put_enclosure:this.filelist1
          }
          console.log(data)
          putSample(data).then(res=>{
            if(res.code==200){
              console.log(res.data)
              this.$message.success('放样成功')
              this.openF = false;
              this.handleClose()
              // this.getDetail(this.id)
            }
          })
        }).catch(err => {
          console.log(err)
        })
          // let data = {
          //   id:this.data.plan.id,
          //   put_sample_id:this.id1,
          //   batch_no:ph,
          //   instrument:this.num,
          //   // instrument:{
          //   //   instrument_id:this.form.num.instrument_id,
          //   //   instrument_name:this.form.num.instrument_name,
          //   //   instrument_no:this.form.num.instrument_no,
          //   //   brand_model:this.form.num.brand_model,
          //   //   attrs:this.form.num.attrs,
          //   //   locker_id:this.form.num.locker_id,
          //   //   locker_name:this.form.num.locker_name
          //   // },
          //   operation_num:Number(this.form.fnum),
          //   if_packing:Number(this.radio),
          //   in_packing:{
          //     in_sealing_ary:checkList,
          //     in_packing_material_ary:this.s1
          //   },
          //   out_packing:{
          //     out_sealing_ary:checkList1,
          //     out_packing_material_ary:this.s2
          //   },
          //   secondary_measure_id:this.secondary_measure_id,
          //   secondary_measure_name:this.secondary_measure_name,
          //   put_enclosure:this.filelist1
          // }
          // console.log(data)
          // putSample(data).then(res=>{
          //   if(res.code==200){
          //     console.log(res.data)
          //     this.$message.success('放样成功')
          //     this.openF = false;
          //     this.handleClose()
          //     // this.getDetail(this.id)
          //   }
          // })
          }
      })
     }
  }
};
</script>
<style scoped>
/* @import url(); 引入css类 */
.el-row {
  display: flex;
  justify-content: space-between;
  flex-flow: wrap;
}
::v-deep .el-button--text {
  padding: 0;
  margin: 0 !important;
  margin-right: 10px !important ;
}
  .preview-container .files-list-container .files-ul[data-v-7beeffa2] {
    width: 100%;
    padding-left: 30px!important;
    /* display: -webkit-box; */
    display: -ms-flexbox;
    /* display: flex; */
    /* -webkit-box-pack: start; */
    -ms-flex-pack: start;
    /* justify-content: flex-start; */
    /* -webkit-box-align: start; */
    -ms-flex-align: start;
    /* align-items: flex-start; */
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
}
</style>
<style>
.tt .el-table__row>td{
  border: none;
}
/* 去掉上面的线 */
.tt .el-table th.is-leaf{
  border: none;
}
/* 去掉最下面的那一条线 */
.tt .el-table::before {
  height: 0px;
}
.ps .preview-container .files-list-container .files-ul[data-v-7beeffa2] {
    width: 100%;
    padding-left: 30px!important;
    /* display: -webkit-box; */
    display: -ms-flexbox;
    /* display: flex; */
    /* -webkit-box-pack: start; */
    -ms-flex-pack: start;
    /* justify-content: flex-start; */
    /* -webkit-box-align: start; */
    -ms-flex-align: start;
    /* align-items: flex-start; */
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
}
</style>
